package com.damon.dm_mail.mapper;

import com.damon.dm_mail.pojo.Email;
import com.damon.dm_mail.pojo.Sender;
import com.damon.dm_mail.pojo.SenderCounter;
import com.damon.dm_mail.pojo.UserInfo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface MailMapper {
    @Select("SELECT * FROM userinfo")
    public List<UserInfo> queryAllUserInfo();

    @Select("SELECT * \n" +
            "\tFROM sender  \n" +
            "\tWHERE id >= (\n" +
            "\t\t(SELECT MAX(id) FROM sender )-(SELECT MIN(id) FROM sender )) * RAND() + (SELECT MIN(id) FROM sender )  \n" +
            "LIMIT 1\n")
    public List<Sender> queryAllSender();

    @Select("select * from sender where id = 12")
    public Sender queryASender();

    @Select("SELECT * FROM userinfo limit #{start},#{end}")
    public List<UserInfo> queryUserInfosByNum(@Param("start") int start, @Param("end") int end);

    @Select("SELECT * FROM userinfo  where id = #{id}")
    public UserInfo queryUserInfoById(@Param("id") int id);

    @Update("update sender_counter set lastIndex = #{lastIndex} where id = 1")
    public void saveLastIndex(@Param("lastIndex") int lastIndex);

    @Select("select * from sender_counter limit 1")
    public SenderCounter getSenderCounter();

    @Select("SELECT * FROM mail")
    public List<Email> queryAllMail();

}
